"use strict";

const browserSync = require("browser-sync");
const webpack = require("webpack");
const webpackDevMiddleware = require("webpack-dev-middleware");
const webpackHotMiddleware = require("webpack-hot-middleware");
const webpackConfig = require("./webpack.config");
const bundler = webpack(webpackConfig);
const bs = browserSync.create();
const proxyMiddleware = require("http-proxy-middleware");

const proxy = proxyMiddleware("/shop", {
    target: "http://www.weixin.com",
    changeOrigin: true,
    logLevel: "debug"
});

bs.init({
    logPrefix: "AMT",
    ui: {
        port: 5081,
        weinre: {
            port: 9090
        }
    },
    port: 5080,
    open: "external",
    host: "192.168.10.221",
    server: {
        baseDir: ["dist"],
        middleware: [
            webpackDevMiddleware(bundler, {
                publicPath: webpackConfig.output.publicPath,
                stats: { colors: true }
            }),
            proxy,
            webpackHotMiddleware(bundler)
        ]
    }
});
